package Test11_08;

import java.util.*;
public class ArrayListTest {
    public static void main(String[] args) {
        //向ArrayList和LinkedList加入10万个对象,比较性能;再随机删除100个,比较时间.
        long stat = System.nanoTime();
        ArrayList list = new ArrayList();
        for (int i = 0; i < 20; i++) {
            list.add(new Integer(i));
            System.out.println(list);
        }
        long end = System.nanoTime();
        System.out.println("添加这么多数需要" + (end-stat) + "的时间");

        long stat1 = System.nanoTime();
        LinkedList linkedList = new LinkedList();
        for (int i = 0; i < 20; i++) {
            linkedList.add(new Integer(i));
            //System.out.println(linkedList);
        }
        long end1 = System.nanoTime();
        System.out.println("添加这么多数需要" + (end1-stat1) + "的时间");

        //从list删除10个数
        for (int i = 0; i < 10; i++) {
            int index = (int) (Math.random() * 10);
            list.remove(new Integer(i));
            //System.out.println(list);
        }
//从linkedList删除10个数
        for (int i = 0; i < 10; i++) {
            int index = (int) (Math.random() * 10);
            linkedList.remove(new Integer(i));
           // System.out.println(linkedList);
        }

    }
}
